﻿using System;
using Flagwind.Services;
using Flagwind.Resources;

namespace Flagwind.Collections.Commands
{
	[CommandOption("queues", Type = typeof(string), Description = "${Text.QueueCommand.Options.Queues}")]
	public class QueueClearCommand : CommandBase<CommandContext>
	{
		#region 构造方法

		public QueueClearCommand() : this("Clear")
		{
		}

		public QueueClearCommand(string name) : base(name)
		{
		}

		#endregion

		#region 执行方法

		protected override object OnExecute(CommandContext context)
		{
			var queues = QueueCommandHelper.GetQueues(context.CommandNode, context.Expression.Options.GetValue<string>("queues"));

			foreach(var queue in queues)
			{
				queue.Clear();
			}

			//显示执行成功的信息
			context.Output.WriteLine(ResourceUtility.GetString("Text.CommandExecuteSucceed"));

			return null;
		}

		#endregion
	}
}